import { observable, action, autorun,toJS } from 'mobx';
import {WeaTableNew,WeaForm} from 'comsMobx'
const {TableStore} = WeaTableNew;
import { ListStore } from './listStore';
import {Modal} from 'antd';
import {WeaTools} from "ecCom"
import * as  Apis from '../apis/report';

export default class CptReportStore  extends ListStore{	
    title = "资产组报表";
    @observable rightMenu =[];
    @observable condition = [];
    @observable searchParams = {};

    @observable verified = false;
	@observable hasRight = false; //权限
    
    @action
    initData=(params={})=>{
        this.form = new WeaForm();
        Apis.getReportCondition(params).then(data=>{
            if(!data.isright  && typeof(data.isright) !== "undefined"){
                this.hasRight = false;
				this.verified = true;
            }else{
                this.hasRight = true;
                this.verified = true;
                this.title = data.title;
                this.condition = data.condition;
                this.form && !this.form.isFormInit && this.form.initFormFields(data.condition);
                this.doSearch(params);
            }
        })
    }
    doSearch = (params={}) =>{
        this.loading = true;
		 //获取表单的参数值
		 const searchParamsAd = this.form.getFormParams();
		 const newParams = { ...this.searchParams, ...searchParamsAd, ...params };
        Apis.getReportList(newParams).then(data=>{
			this.tableStore.getDatas(data.sessionkey,  params.current || 1);
			this.searchParams = { ...this.searchParams, ...params };
			this.dataKey = data.sessionkey;
			this.rightMenu = data.rightMenus;
            this.loading = false;
        })
    }

    clearStatus=()=>{
        this.rightMenu =[];
        this.condition = [];
        this.searchParams = {};
        this.verified = false;
	    this.hasRight = false; 
    }

}
